﻿using System;
using System.Security;
using System.Text;

namespace Pscx.Commands.IO.Compression.ArchiveReader
{
    /// <summary>
    /// Represents an entry in a compressed archive, like a ZIP or TAR file.
    /// This class only contains metadata about the entry.
    /// </summary>
    [Serializable]
    public class ArchiveEntry
    {
        private readonly uint _index;
        private readonly string _path;
        private readonly long _size;
        private readonly long _compressedSize;
        private readonly DateTime _modifiedDate;
        private readonly string _name;
        private readonly bool _isEncrypted;
        private readonly bool _isFolder;
        private readonly string _archivePath;
        private readonly ArchiveFormat _format;

        internal ArchiveEntry(uint index, string path, long size, long compressedSize, DateTime modifiedDate, string name, bool isEncrypted, bool isFolder, string archivePath, ArchiveFormat format)
        {
            _index = index;
            _path = path;
            _size = size;
            _compressedSize = compressedSize;
            _modifiedDate = modifiedDate;
            _name = name;
            _isEncrypted = isEncrypted;
            _isFolder = isFolder;
            _archivePath = archivePath;
            _format = format;
        }

        internal SecureString Password { get; set; }

        /// <summary>
        /// Index of item in archive directory.
        /// </summary>
        public uint Index
        {
            get { return _index; }
        }

        /// <summary>
        /// kpidPath
        /// </summary>
        public string Path
        {
            get { return _path; }
        }

        /// <summary>
        /// kpidSize
        /// </summary>
        public long Size
        {
            get { return _size; }
        }

        /// <summary>
        /// kpidPackedSize
        /// </summary>
        public long CompressedSize
        {
            get { return _compressedSize; }
        }

        /// <summary>
        /// kpidLastWriteTime
        /// </summary>
        public DateTime ModifiedDate
        {
            get { return _modifiedDate; }
        }

        /// <summary>
        /// kpidName
        /// </summary>
        public string Name
        {
            get { return _name; }
        }

        /// <summary>
        /// Does this entry come from an encrypted archive?
        /// </summary>
        public bool IsEncrypted
        {
            get { return _isEncrypted; }
        }

        /// <summary>
        /// Does this entry represent a folder in the archive?
        /// </summary>
        public bool IsFolder
        {
            get { return _isFolder; }
        }

        internal ArchiveFormat Format
        {
            get { return _format; }
        }

        /// <summary>
        /// The full path to the containing archive file, e.g. foo.zip
        /// </summary>
        public string ArchivePath
        {
            get
            {
                return _archivePath;
            }
        }
    }
}
